#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e4 + 5;
const int MX = 60;

int n, m;
ll g[N];
int dep[N];
int f[N][16];
ll st[N][16][64];
int head[N];
int ver[N << 1], Next[N << 1], tot;
void add(int u, int v) {
  ++tot;
  ver[tot] = v;
  Next[tot] = head[u];
  head[u] = tot;
}
void insert(ll p[64], ll x) {
  per(i, MX, 0) {
    if (x >> i) {
      if (p[i])
        x ^= p[i];
      else {
        p[i] = x;
        return;
      }
    }
  }
}
void insert(ll p[64], ll a[64]) { per(i, MX, 0) if (a[i]) insert(p, a[i]); }
void dfs(int u, int fu) {
  dep[u] = dep[fu] + 1;
  f[u][0] = fu;
  insert(st[u][0], g[u]);
  // insert(st[u][0], g[fu]);
  for (int i = head[u]; i; i = Next[i]) {
    int v = ver[i];
    if (v == fu) continue;
    dfs(v, u);
  }
}
void init_st() {
  rep(i, 1, 14) {
    rep(u, 1, n) {
      f[u][i] = f[f[u][i - 1]][i - 1];
      insert(st[u][i], st[u][i - 1]);
      insert(st[u][i], st[f[u][i - 1]][i - 1]);
    }
  }
}
ll query(ll p[64]) {
  ll ans = 0;
  per(i, MX, 0) ans = max(ans, ans ^ p[i]);
  return ans;
}
ll lca(int u, int v) {
  ll p[64] = {0};
  if (dep[u] < dep[v]) swap(u, v);
  int d = dep[u] - dep[v];
  per(i, 14, 0) {
    if (d & (1 << i)) {
      insert(p, st[u][i]);
      u = f[u][i];
    }
  }
  if (u == v) {
    insert(p, g[u]);
    return query(p);
  }
  per(i, 14, 0) {
    if (f[u][i] != f[v][i]) {
      insert(p, st[u][i]);
      insert(p, st[v][i]);
      u = f[u][i], v = f[v][i];
    }
  }
  insert(p, g[u]);
  insert(p, g[v]);
  insert(p, g[f[u][0]]);
  return query(p);
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 1, n) cin >> g[i];
  rep(i, 2, n) {
    int u, v;
    cin >> u >> v;
    add(u, v), add(v, u);
  }
  dfs(1, 0);
  init_st();
  while (m--) {
    int u, v;
    cin >> u >> v;
    cout << lca(u, v) << endl;
  }
  return 0;
}